/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!		\file		PrpTpl.cc
		\date		june 2010
		\author		TNick

		\brief		Contains the implementation of PrpTpl class and related


	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Please read ReadMe.txt and Licence.txt in root folder
	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	"prpmdl.h"
#include	"prptpl.h"

#include	<QDebug>


/*  INCLUDES    ============================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

/* ------------------------------------------------------------------------- */
PrpTpl::PrpTpl		(PrpMdl* pa_mdl, PrpNode* pa_fth,
					 TYPE a_it_ty, QString stra_name, QString stra_descr)
						 : CC_L2D ()
{
	/* save known value */
	flg = FNONE;
	str_name = stra_name;
	str_descr = stra_descr;
	it_ty = a_it_ty;
	p_father = NULL; // act as if you don't know that this is a union
	p_model = NULL;


	/* insert in chain */
	if (pa_mdl == NULL)
		{
			if (pa_fth != NULL)
				{
					pa_mdl = pa_fth->model();
				}
		}

	if (pa_fth == NULL)
		{ /* root item */
			if (pa_mdl != NULL)
				{
					setModel(pa_mdl);
					pa_mdl->append(this);
				}
			else
				flg = static_cast<FLAGS>(flg | FROOTITEM);
		}
	else
		{ /* leaf item */
			setParent(pa_fth);
			pa_fth->append(this);
		}

}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
int					PrpTpl::row				(void)
{
	if (isTopLevel())
		{ /* this is a top level item */
			return index(&p_model->hd);
		}
	else
		{ /* this is NOT a top level item */
			return index(&p_father->hd);
		}
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
PrpMdl*				PrpTpl::model		(void)
{
	PrpNode*	pItr = (PrpNode*)this;
	while (pItr->isTopLevel() == false)
		{ pItr = pItr->parent(); }
	return pItr->p_model;
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void				PrpTpl::informParent	(void)
{
	if (isInferior())
		{
			Q_ASSERT(!isTopLevel());
			p_father->subChanged(this);
		}
}
/* ========================================================================= */

/*  CLASS    =============================================================== */
//
//
//
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
